package main

import (
	"gitee.com/gopher2011/go-grpc-test/server/services"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"
	"log"
	"net"
)

func main(){
	//// 不添加证书连接服务器
	//// 新建服务
	//rpcServer := grpc.NewServer()
	//// 注册服务
	//services.RegisterProductServiceServer(rpcServer,new(services.ProbService))
	//// 运行服务
	//lis,_ :=net.Listen("tcp",":8081")
	//rpcServer.Serve(lis)

	// 添加证书连接服务器
	creds,err := credentials.NewServerTLSFromFile("server/keys/server.crt", "server/keys/server_no_passwd.key")
	if err != nil {
		log.Fatalf("加载服务端证书和Key失败, err: %v\n",err)
	}
	rpcServer := grpc.NewServer(grpc.Creds(creds))
	services.RegisterProductServiceServer(rpcServer,new(services.ProbService))
	listen,err := net.Listen("tcp",":8081")
	if err != nil {
		log.Fatalf("启动网络监听失败 %v\n",err)
	}
	rpcServer.Serve(listen)
}


